Add --exclude flag
authortorkleyy <thomas-schaller2000@gmx.de>
Thu, 11 May 2017 18:47:48 +0000 (20:47 +0200)
committertorkleyy <thomas-schaller2000@gmx.de>
Sat, 27 May 2017 18:33:00 +0000 (20:33 +0200)
Allows to exclude packages in conjunction
with --all.

src/bin/build.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_run.rs

index 731d563c97738d5a92cf555ac444388f9f6e5ba5..650e256dafeb6eed157ef0cd25f4d23e40b5ffd3 100644 (file)
@@ -31,6 +31,7 @@ pub struct Options {
     flag_locked: bool,
     flag_frozen: bool,
     flag_all: bool,
+    flag_exclude: Vec<String>,
 }
 
 pub const USAGE: &'static str = "
@@ -43,6 +44,7 @@ Options:
     -h, --help                   Print this message
     -p SPEC, --package SPEC ...  Package to build
     --all                        Build all packages in the workspace
+    --exclude SPEC ...           Exclude packages from the build
     -j N, --jobs N               Number of parallel jobs, defaults to # of CPUs
     --lib                        Build only this package's library
     --bin NAME                   Build only the specified binary
@@ -73,6 +75,7 @@ current package is built. For more information on SPEC and its format, see the
 
 All packages in the workspace are built if the `--all` flag is supplied. The
 `--all` flag may be supplied in the presence of a virtual manifest.
+Note that `--exclude` has to be specified in conjunction with the `--all` flag.
 
 Compilation can be configured via the use of profiles which are configured in
 the manifest. The default profile for this command is `dev`, but passing
@@ -90,10 +93,12 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
 
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
 
-    let spec = if options.flag_all {
-        Packages::All
-    } else {
-        Packages::Packages(&options.flag_package)
+    let spec = match (options.flag_all, &options.flag_exclude) {
+        (true, exclude) if exclude.is_empty() => Packages::All,
+        (true, exclude) => Packages::OptOut(exclude),
+        (false, exclude) if !exclude.is_empty() => panic!("--exclude can only be used together \
+                                                           with --all"),
+        _ => Packages::Packages(&options.flag_package),
     };
 
     let opts = CompileOptions {
index 8506a4523a3d3e446eaf66c90a31992c0991a4b0..59e9fbcb74c864815f4780d160e43481d9fc4ff7 100644 (file)
@@ -105,6 +105,7 @@ pub enum MessageFormat {
 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
 pub enum Packages<'a> {
     All,
+    OptOut(&'a [String]),
     Packages(&'a [String]),
 }
 
@@ -117,6 +118,13 @@ impl<'a> Packages<'a> {
                     .map(PackageIdSpec::from_package_id)
                     .collect()
             }
+            Packages::OptOut(opt_out) => {
+                ws.members()
+                    .map(Package::package_id)
+                    .map(PackageIdSpec::from_package_id)
+                    .filter(|p| opt_out.iter().position(|x| *x == p.name()).is_none())
+                    .collect()
+            }
             Packages::Packages(packages) => {
                 packages.iter().map(|p| PackageIdSpec::parse(&p)).collect::<CargoResult<Vec<_>>>()?
             }
index 47d18a981716945ea987f9973e48cb82a8341334..e631e503dc1ed3af63d492113b911f74bece20c8 100644 (file)
@@ -11,6 +11,7 @@ pub fn run(ws: &Workspace,
 
     let pkg = match options.spec {
         Packages::All => unreachable!("cargo run supports single package only"),
+        Packages::OptOut(_) => unreachable!("cargo run supports single package only"),
         Packages::Packages(xs) => match xs.len() {
             0 => ws.current()?,
             1 => ws.members()